const Audio = (function() {
  const dom = {
    audio: document.querySelector('audio'),
    playSwitch: document.querySelector('.play-switch')
  }

  bindEvent()

  function bindEvent() {
    dom.playSwitch.addEventListener('click', playSwitchHandle)
  }

  /**
   * 音频播放
   */
  function audioPlay() {
    dom.audio.play()
  }

  /**
   * 音频暂停
   */
  function audioPaused() {
    dom.audio.pause()
  }

  /**
   * 判断音频状态
   */
  function isPaused() {
    if (dom.audio.paused) {
      dom.playSwitch.innerHTML = '关闭'
    } else {
      dom.playSwitch.innerHTML = '开启'
    }
  }

  function autoPlay() {
    dom.playSwitch.style.opacity = 1
    audioPlay()
  }

  /**
   * 音频处理
   */
  function playSwitchHandle() {
    if (dom.audio.paused) {
      audioPlay()
    } else {
      audioPaused()
    }
    isPaused()
  }

  return {
    autoPlay
  }
})()
